<?php
	require_once("logic/chksession.php");
	
	
	require_once("logic/config.php");
	
	//Connect to server and select database.
				mysql_connect($db_server,$db_user,$db_pass)or die("cannot connect to server");
				mysql_select_db($db_database)or die("cannot select DB");
				
				// table name
				$tbl_name1="user_books";
				$tbl_name2="book_info";
				$user_id=$_SESSION['user_id'];
				
				

                $sql = "select * from $tbl_name2 tb2,$tbl_name1 tb1 where tb2.isbn=tb1.isbn and tb1.user_id=$user_id ";
                $result = mysql_query($sql);
                $count=mysql_num_rows($result);
				
                
?>
<!doctype html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]>    <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]>    <html class="no-js lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

	<title></title>
	<meta name="description" content="">
	<meta name="author" content="">

	<meta name="viewport" content="width=device-width">

	<link rel="stylesheet" href="css/bootstrap.min.css">
	<style>
	body {
	  padding-top: 60px;
	  padding-bottom: 40px;
	}
	</style>
	<link rel="stylesheet" href="css/bootstrap-responsive.min.css">
	<link rel="stylesheet" href="css/style.css">
	
	<script src="js/libs/modernizr-2.5.3-respond-1.1.0.min.js"></script>
</head>
<body>
<!--[if lt IE 7]><p class=chromeframe>Your browser is <em>ancient!</em> <a href="http://browsehappy.com/">Upgrade to a different browser</a> or <a href="http://www.google.com/chromeframe/?redirect=true">install Google Chrome Frame</a> to experience this site.</p><![endif]-->

    <div class="navbar navbar-fixed-top">
      <div class="navbar-inner">
        <div class="container">
          <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </a>
          <a class="brand" href="index.php">E-library</a>
          <div class="nav-collapse">
            <ul class="nav">
              <li class="active"><a href="index.php">Home</a></li>
              <?php
               if(isset($_SESSION['user_id'])){ ?>
				  
				 <li><a href="addcredit.php">Add Credit</a></li>
				  <li><a href="logic/logout.php">Log Out</a></li>
                   <li><a href="my-downloads.php">My Downloads</a></li>
                  
                  <?php
				   } 
				  else {
				  ?>
				  <li><a href="register.php">Register</a></li>
				  <li><a href="login.php">Log In</a></li>
                  
                  <?php }?>
			 
            </ul>
          </div><!--/.nav-collapse -->
        </div>
      </div>
    </div>

<div class="container">

	<?php if($count>=1)
                {
                    
                ?>	
                <h3>Following are the Books downloaded</h3>
                <hr>

	<table class="table-bordered table">
    	
        <thead>
        	<tr>
            
            <th>Title</th>
            <th>Author</th>
            <th>Price</th>
            <th>ISBN</th>
            <th>Download</th>
            </tr>
            
        </thead>
        	
            <tbody>
        	
            
            
             <?php	while ($row = mysql_fetch_array($result)) {
                        
                  echo "<tr>";  
					  echo "<td>" . $row['title'] . "</td>";
                      echo "<td>" . $row['author'] . "</td>";
                      echo "<td>" . $row['price'] . "</td>";
					  echo "<td>" . $row['isbn'] . "</td>";
                      
                      echo "<td><a href='books/". $row['file_path'] ."' class='btn btn-primary'>Download</a></td>";
                     
					 echo "</tr>";
                      }
                     
                    
                ?> 
            
           
        </tbody>
    </table>
<?php 

				} 
			else{
				echo "No eboks downloaded yet";
				}
?>
</div>
</body>
</html>